﻿Imports drawing.CommonInterfaces.UI.interfaces

Namespace world.environement

    Public Class World
        Implements IViewable, ITickable

        Public population As ICollection(Of ITickable)
        Public _size As Rectangle
        
        Private Sub New()
            population = New List(Of ITickable)

        End Sub

        Public Sub New(ByVal size As Rectangle)
            Me._size = size
            population = New List(Of ITickable)
        End Sub

        Public Sub add(ByVal obj As ITickable)
            obj.ID = population.Count + 1
            population.Add(obj)
        End Sub

        Public Sub MoveForSelected(ByVal destination As Point)
            Dim selected As ICollection(Of ISelectable) = getSelected()
            For Each obj As Object In selected
                If TypeOf obj Is IMovable Then
                    DirectCast(obj, IMovable).destination = destination
                End If
            Next

        End Sub

        Public Function getSelected() As ICollection(Of ISelectable)
            Dim result As ICollection(Of ISelectable) = New List(Of ISelectable)
            For Each obj As Object In Me.population
                If TypeOf obj Is ISelectable Then
                    If DirectCast(obj, ISelectable).selected Then
                        result.Add(obj)
                    End If

                End If
            Next
            Return result
        End Function

        Public Function selectedNumber() As Integer
            Dim result As Integer = 0
            For Each obj As Object In population
                If TypeOf obj Is ISelectable Then
                    If DirectCast(obj, ISelectable).selected Then
                        result += 1
                    End If
                End If
            Next

            Return result
        End Function


        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub thick() Implements ITickable.tick

            For Each obj As ITickable In population
                obj.tick()
            Next
        End Sub

        Public Sub clear()
            population = New List(Of ITickable)
        End Sub

        Public Sub draw(ByRef graph As System.Drawing.BufferedGraphics) Implements IViewable.draw
            graph.Graphics.Clear(Color.Black)
            For Each obj As IViewable In population
                obj.draw(graph)
            Next
        End Sub

        Public Sub resetSize(ByVal size As System.Drawing.Rectangle) Implements IViewable.resetSize
            For Each obj As IViewable In population
                obj.resetSize(size)
            Next
        End Sub

        Public Property ID() As Double Implements ITickable.ID
            Get
                Return 0
            End Get
            Set(ByVal value As Double)

            End Set
        End Property
    End Class

End Namespace
